<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/common.php';

$item_id = $_GET['item_id'];
$item = item::getById($item_id);
$user_id = user::getId();
if (empty($user_id) || empty($item))
{
	echo json_encode(array('result'=>false,'code'=>1));
	return false;
}

if ($item['user_id'] == $user_id)
{
	echo json_encode(array('result'=>false,'code'=>2));
	return false;
}

$reply = $_POST['reply'];
$rate = $_POST['rate'];

$reply_id = item::reply($item_id, $reply);
$rate_id = item::rate($item_id, $rate);

if ($reply_id)
{
	echo json_encode(array('result'=>true,'reply_id'=> $reply_id,'rate_id'=> $rate_id));
} else {
	echo json_encode(array('result'=>false,'code'=>3));
}
